package net.haiyue.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.haiyue.api.custom.JsonResult;
import net.haiyue.api.entity.Project;
import net.haiyue.api.service.ProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "UserController")
@RestController
@RequestMapping(value = "/project")
public class ProjectController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private ProjectService _service;

    @Autowired
    HttpServletRequest request;

    @ApiOperation(value="获取所有的项目信息", notes="用于表格展示")
    @GetMapping("/index")
    public JsonResult Index(){
        return JsonResult.success( _service.all());
    }
    @GetMapping("/select")
    public  JsonResult Select(){
        //获取email
        String email = request.getHeader("email");
        return JsonResult.success(_service.selectProject(email));
    }
    @PostMapping("/add")
    public JsonResult Add(@RequestBody Project project){
        return JsonResult.success(_service.add(project));
    }

}
